package jdbctest;

import pojo.Account;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 * @author tongchen
 * @create 2022-11-03 16:55
 */
public class JdbcTest4 {
    public static void main(String[] args) throws Exception {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接
        String url="jdbc:mysql://127.0.0.1:3306/exer?useSSL=false";
        String username="root";
        String password="abc123";
        Connection connection = DriverManager.getConnection(url, username, password);
        //3.定义sql语句
        String pwd="1234";
        String name="zhangsan";
        String sql="select*from tb_user where username='"+name+"'and password ='"+pwd+"'";
        //4.创建sql对象
        Statement statement = connection.createStatement();
        //5.执行sql语句
        ResultSet resultSet = statement.executeQuery(sql);//(使用查询类型的语句)
        //6.处理返回结果
        if(resultSet.next()){
            System.out.println("登陆成功");
        }else{
            System.out.println("登陆失败");
        }

        //7.关闭资源
        resultSet.close();
        statement.close();
        connection.close();


    }
}
